package wetogether.community.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;



import wetogether.community.util.CommonConstants;
import wetogether.community.vo.AttachmentVO;
import wetogether.community.vo.BoardVO;
import wetogether.community.vo.CommentsVO;

public class QnaBoardDAOImpl extends SqlMapClientDaoSupport implements BoardDAO {
	private Log log=LogFactory.getLog(getClass());
	
	/**
	 * Delete All Comments By Content ID
	 * @param contentID
	 */
	@Override
	public void deleteAttachment(int contentId) {

	}

	@Override
	public void deleteComments(int commentsId) {

	}

	@Override
	public void deleteContent(int contentId) {
		getSqlMapClientTemplate().delete("qna.deleteContent",contentId);
	}

	@Override
	public ArrayList<BoardVO> findContentByName(String name, int boardId,
			int locationId) {
		return null;
	}

	@Override
	public ArrayList<BoardVO> findContentByTitle(String title, int boardId,
			int locationId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public AttachmentVO getAttachment(int contentId) {
		return (AttachmentVO)getSqlMapClientTemplate().queryForObject("qna.getAttachment", contentId);
	}

	@Override
	public ArrayList<CommentsVO> getCommentsList(int contentId) {
		return null;		
	}
	/** 
	 * Date : 2010-11-10
	 * Author : Shin In-soo
	 * Comments : 글보기
	 * @param contentId
	 * @return BoardVO
	 */
	@Override
	public BoardVO getContent(int contentId) {
		log.debug("[DAO]in getContent");
		BoardVO vo=(BoardVO)getSqlMapClientTemplate().queryForObject("qna.getContent", contentId);
		log.debug("return BoardVO: "+vo);
		return vo;
	}

	@Override
	public ArrayList<BoardVO> getContentList(int locationId, int boardId,
			int page) {
		log.debug("[DAO]getContentList");
		log.debug("locId="+locationId+" boardId="+boardId+" page="+page);
		Map map=new HashMap();
		map.put("locationId", locationId);
		map.put("boardId", boardId);
		map.put("page", page);
		map.put("CONTENT_NUMBER_PER_PAGE",CommonConstants.CONTENT_NUMBER_PER_PAGE);
		ArrayList<BoardVO> list=(ArrayList<BoardVO>)getSqlMapClientTemplate().queryForList("qna.getContentList", map);
		return list;
	}
	

	@Override
	public String getDate(int seq) {
		System.out.println("in getDate");
		return (String)getSqlMapClientTemplate().queryForObject("qna.getDate", seq); 
	}

	@Override
	public int getSelectAttachmentSeq() {
		System.out.println("in getSelectAttachmentSeq");
		return (Integer)getSqlMapClientTemplate().queryForObject("qna.getSelectAttachmentSeq");
	}

	@Override
	public int getSelectCommentsSeq() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getSelectContentSeq() {
		System.out.println("in getSelectContentSeq");
		return (Integer)getSqlMapClientTemplate().queryForObject("qna.getSelectContentSeq");
	}

	@Override
	public void insertAttachment(AttachmentVO attachmentVO) {
		System.out.println("[DAO]in insertAttachment");
		System.out.println(attachmentVO);
		getSqlMapClientTemplate().insert("qna.insertAttachment", attachmentVO);
	}

	@Override
	public void insertComments(CommentsVO commentsVO) {

	}

	@Override
	public void insertContent(BoardVO boardVO) {
		System.out.println("in insertContent");
		System.out.println(boardVO);
		getSqlMapClientTemplate().insert("qna.insertContent", boardVO);
	}

	@Override
	public void updateContent(BoardVO boardVO) {
		
	}

	@Override
	public void updateHits(int contentId) {
		System.out.println("[DAO]in updateHits");
		getSqlMapClientTemplate().update("qna.updateHits", contentId);
	}	
	@Override
	public int checkGroupPosition(BoardVO boardVO) {
		System.out.println("[DAO]in checkGroupPosition");
		return (Integer)getSqlMapClientTemplate().queryForObject("qna.checkGroupPosition", boardVO);
	}

	@Override
	public int findMaxGroupPosition(BoardVO boardVO) {
		System.out.println("in findMaxGroupPosition");
		return (Integer)getSqlMapClientTemplate().queryForObject("qna.findMaxGroupPosition", boardVO);
	}

	@Override
	public void updatePositionNumber(BoardVO boardVO) {
		System.out.println("in updatePositionNumber");
		getSqlMapClientTemplate().update("qna.updatePositionNumber", boardVO);
	}

	@Override
	public int getTotalContents(int boardId, int locationId) {
		Map map=new HashMap();
		map.put("locationId", locationId);
		map.put("boardId", boardId);
		return (Integer)getSqlMapClientTemplate().queryForObject("qna.getTotalContents", map);
	}

}
